﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fierce.Core.Aop;
using Fierce.Entity.Basic;

namespace Fierce.Core.Service.Basic
{
    public partial class BasicRoleMenuFunctionService : BaseService<BasicRoleMenuFunction>
    {
        public virtual List<BasicRoleMenuFunction> GetByRoleId(string roleId)
        {
            return db.BasicRoleMenuFunction.Query(m => m.RoleID == roleId).ToList();
        }

        public virtual ServiceResult SetMenuFunction(string roleId, string[] menufunctionIds)
        {
            db.BasicRoleMenuFunction.Deleted(m => m.RoleID == roleId);

            var list = new List<BasicRoleMenuFunction>();

            foreach (var menufunctionid in menufunctionIds)
            {
                if (!string.IsNullOrEmpty(menufunctionid))
                {
                    var entity = new BasicRoleMenuFunction();

                    entity.RoleID = roleId;
                    entity.MenuFunctionID = menufunctionid;

                    list.Add(entity);
                }
            }

            db.BasicRoleMenuFunction.Added(list);

            return SaveAndResult("设置成功");
        }
    }
}
